package com.netease.nie.utils;

import org.apache.log4j.Logger;

import com.netease.nie.dto.ClickDto;
import com.netease.nie.dto.LoginLogoutDto;
import com.netease.nie.dto.PageViewDto;

/**
 * 系统日志工具类
 * @author Derek Xu
 * @CreateDate Aug 12, 2016
 */
public class LogUtils {

	/**
	 * 日志名称参考log4j.properties中的配置
	 */
	private static final String LOGIN_LOGGER_NAME = "kh.user-login";		//登录日志名称
	private static final String LOGOUT_LOGGER_NAME = "kh.user-logout";		//登出日志名称
	private static final String PAGE_VIEW_LOGGER_NAME = "kh.page-view";	//页面访问日志名称
	private static final String CLICK_LOGGER_NAME = "kh.click";			//点击监控日志名称
	
	/**
	 * 登录日志记录
	 */
	public static void logLogin(LoginLogoutDto loginLogoutDto) {
		String content = loginLogoutDto.toString();
		log(LOGIN_LOGGER_NAME, content);
	}
	
	/**
	 * 登出日志记录
	 */
	public static void logLogout(LoginLogoutDto loginLogoutDto) {
		String content = loginLogoutDto.toString();
		log(LOGOUT_LOGGER_NAME, content);
	}
	
	/**
	 * 页面访问日志记录
	 */
	public static void logPageView(PageViewDto pageViewDto) {
		String content = pageViewDto.toString();
		log(PAGE_VIEW_LOGGER_NAME, content);
	}
	
	/**
	 * 点击监控日志记录
	 */
	public static void logClick(ClickDto clickDto) {
		String content = clickDto.toString();
		log(CLICK_LOGGER_NAME, content);
	}
	
	
	/**
	 * 记录日志
	 * @param loggerName 对应log4j.properties中的日志名称
	 * @param content 日志记录的内容
	 */
	private static void log(String loggerName, String content) {
		Logger logger = Logger.getLogger(loggerName);
		logger.info(content);
	}
}
